# koroFileHeader at Yungoal acer
# Create: 2022-10-08 15:39:12
# LastEdit: 2022-10-08 17:50:48
"""说明暂无"""
__author__ = '749B'

from django.conf import settings
from django.db import models

from utils.vault import encrypt

class Account(models.Model):
    name = models.CharField(max_length=32, verbose_name='公司名称')
    enrollment = models.CharField(max_length=32, verbose_name='合约编号')
    access_key = models.TextField(max_length=4096, verbose_name="辅助密钥") 

    def __str__(self):
        return f'{self.enrollment} {self.name}'

    def save(self, *args, **kwargs):
        """重写save方法"""
        # 在save之前对access_key加密
        self.access_key = encrypt(self.access_key, settings.VAULT_PASSWORD)
        # 只允许有1条记录，写入前把之前的删掉
        Account.objects.all().delete()
        super().save(*args, **kwargs)

    class Meta:
        verbose_name = 'EA账号'
        verbose_name_plural = 'EA账号表'
